package org.molamil.acto.types {
	import org.molamil.acto.core.parsers.ParserError;	
	
	/**
	 * Type parser expecting the value passed when <code>parse()</code> to be 
	 * an empty string.
	 * 
	 * <p>Note that <code>value</code> is not trimmed, so in order to return
	 * <code>value</code> an empty string, without empty spaces has to be 
	 * passed.</p>
	 * 
	 * @example The following code will parse "" into <code>null</code>
	 * and will trace "HOLLY COW, I parsed a null!!!":
	 * <listing version="3.0" >
	 * var parser:AbstractTypeParser = new NullTypeParser();
	 * var n:* = parser.parse("");
	 * if (n == null)
	 *    trace("HOLLY COW, I parsed a null!!!");
	 * </listing>
	 * 
	 * @author Jorge Hernandez
	 */
	public class NullTypeParser extends AbstractTypeParser {
		
		
		// CONSTANTS
		
		/**
		 * @inheritDoc
		 */
		public static const PRIORITY:uint = 800;
		
		
		// PUBLIC METHODS
		
		/**
		 * Returns null if <code>value</code> is <code>null</code>, or throws
		 * an <code>Error</code>
		 * 
		 * <p>Note that an empty string will not be parsed to null.</p>
		 * 
		 * <p>In this type parser implementation <code>parse()</code> has been
		 * overriden instead of <code>doParse()</code>, as there is no need for
		 * the extra type checking that <code>AbstractTypeParser.parse()</code>
		 * performs.</p>
		 * 
		 * @param value <code>String</code> value to test
		 * @return <code>null</code> if the value was <code>null</code>
		 * @throws org.molamil.acto.core.errors.ParserError The value is not 
		 * 	<code>null</code>
		 */
		override public function parse(value:String):* {
			if (value == null) {
				return null;
			} else {
				throw new ParserError("ERROR: '" + value + "' cannot be parsed " +
					"into null (is not an empty string)");
			}
		}
		
		
	}
	
}
